<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="common" th:with="title='后台账户管理'"></head>
<body class="hold-transition skin-blue sidebar-mini">

<div th:include="main-header"></div>
<div th:include="model" id="modelHtml"></div>
<div class="content-wrapper">
    <section class="content">
        <div class="panel panel-default">
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel-heading">个人中心</div>
                    <br class="panel-body">
                    <div style="width: 90%;margin-left: 3%">
                        <div id="toolbar" class="btn-group" style="margin-bottom: 18px">
                            <button type="button" class="btn btn-primary" style="width:100px;" id="updateBtn">修改
                            </button>
                        </div>
                        <table class="table table-bordered table-striped">
                            <colgroup>
                                <col class="span1">
                                <col class="span7">
                            </colgroup>
                            <tbody>
                            <tr>
                                <td>
                                    用户名
                                </td>
                                <td>
                                    <span data-th-text="${user.username}"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    key
                                </td>
                                <td>
                                    <span data-th-text="${user.userKey}"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    salt
                                </td>
                                <td>
                                    <span data-th-text="${user.salt}"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    联系人
                                </td>
                                <td>
                                    <span data-th-text="${user.nickname}"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    手机号
                                </td>
                                <td>
                                    <span data-th-text="${user.phone}"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    公司名
                                </td>
                                <td>
                                    <span data-th-text="${user.companyName}"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    公司地址
                                </td>
                                <td>
                                    <span data-th-text="${user.companyAddress}"></span>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                        <table id="blogTable" class="table table-bordered table-hover"></table>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>

<input type="hidden" id="blogId"/>
<input type="hidden" id="userId"/>
<div th:include="main-footer"></div>
<script>
    $(function () {
        //保存修改数据持久化到数据库
        $("#addButton").click(function () {
            check_form();
        });
        //调用修改弹出框
        $("#updateBtn").click(function () {
            remoteFormUrl('修改', '', '/user/update');
        });
    });

    function check_form() {
        if ($("#userForm").length > 0) {
            if (!$("#userForm").valid()) {
                return;
            }
            $.ajax({
                url: "/user/implementUpdate",
                data: $("#userForm").serialize(),
                type: "post",
                async: false,
                success: function (data) {
                    if (data) {
                        if (data.code == 1) {//操作成功
                            $('#addModal').modal('toggle');
                            location.reload();
                        } else {//操作失败
                            $("#msg").html(data.msg);
                        }
                    }
                }
            });
        }
    }

    function remoteFormUrl(modelTitle, recordId, reqUrl) {
        $('#addModal .modal-body').html('');
        $('#addModalTitle').text(modelTitle);
        $.ajax({
            url: reqUrl,
            type: "post",
            data: {"id": recordId},
            async: false,
            success: function (data) {
                $('#addModal .modal-body').html(data);
            }
        });
        $('#addModal').modal({keyboard: true, backdrop: true})
    }
</script>
</body>
</html>